/*                          UX-Framework                               
 *                                                                 
 *  iZE Co.,Ltd. Copyright 2009 All rights reserved.          
 *  This file is distributed under the terms of the GNU Lesser 
 *  General Public License, described in file LICENSE.                                     
 */
package jp.ize.ux.interactions;

// {{{ imports
import jp.ize.ux.UXInteraction;
import jp.ize.ux.events.UXKeyboardEvent;
import flash.events.KeyboardEvent;
// }}}
// {{{ class UXKeyInteraction<S> extends UXGeneralInteraction<S>
/**
 * UXKeyInteraction クラス<br>
 * インタラクションです。
 */
class UXKeyInteraction<S> extends UXInteraction<S>
{
	// {{{ public function new( keyCode:UInt, ?altKey:Bool, ?ctrlKey:Bool, ?shiftKey:Bool ) : Void
	/**
	 * コンストラクタです。
	 */
	public function new( keyCode:UInt, ?altKey:Bool, ?ctrlKey:Bool, ?shiftKey:Bool ) : Void
	{
		super();
		addReactEvent(KeyboardEvent.KEY_DOWN);
		var notAltKey:Bool = false;
		var notCtrlKey:Bool = false;
		var notShiftKey:Bool = false;
		if ( altKey==null ) {
			altKey = false;
			notAltKey = true;
		}
		if ( ctrlKey==null ) {
			ctrlKey = false;
			notCtrlKey = true;
		}
		if ( shiftKey==null ) {
			shiftKey = false;
			notShiftKey = true;
		}
		name = "Key" + Std.string(keyCode);
		judge = function (s:S) {
			var flag:Bool = false;
			var key:KeyboardEvent = Reflect.field(s,"keyboard");
			if ( key.keyCode==keyCode
					&& ( notAltKey || altKey==altKey)
					&& ( notCtrlKey || ctrlKey==ctrlKey)
					&& ( notShiftKey || shiftKey==shiftKey) ) {
				flag = true;
			}
			return flag;
		}
	}
	// }}}
}
// }}}
